import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Person {

	String name;
	String surname;
	String dateOfBirth;
	Car car;

	Person(String name, String surname, String dateOfBirth, Car car) {
		this.name = name;
		this.surname = surname;
		this.dateOfBirth = dateOfBirth;
		this.car = car;
	}

	public static Person[] parseArgsToPersons(String args[]) {
		Person[] persons = new Person[args.length / 5];
		for (Integer i = 0; i < args.length / 5; i++) {
			persons[i] = new Person(args[i * 5 + 0], args[i * 5 + 1],
					args[i * 5 + 2], new Car(args[i * 5 + 3], args[i * 5 + 4]));
		}
		return persons;
	}

	public static void greetPersons(Person[] persons) {
		for (Person person : persons) {
			person.introduceYourSelf(person);
		}
	}

	public static Integer getCurrentYear() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
		Calendar c1 = Calendar.getInstance();
		String currentYear = sdf.format(c1.getTime());
		return Integer.parseInt(currentYear);
	}

	public Integer getPersonAge(Person person) {
		Integer currectYear = getCurrentYear();
		String fullDateOfBirth = person.dateOfBirth;
		fullDateOfBirth = fullDateOfBirth
				.substring(fullDateOfBirth.length() - 4);
		Integer dateOfBirth = currectYear - Integer.parseInt(fullDateOfBirth);
		return dateOfBirth;
	}

	public void introduceYourSelf(Person person) {
		System.out.println("My name is " + person.name + " " + person.surname
				+ ", I'm " + getPersonAge(person) + ". I drive " + car.brand
				+ " which is " + car.getCarAge(car) + " years old.");
	}

}
